﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace CommonLib
{
	public class GameInstantiate : MonoBehaviour
	{
		public List<GameObject> initObjects = new List<GameObject>();
		List<IInstantiate> InitItems = new List<IInstantiate>();

		private void Awake()
		{
			for (int index = 0; index < initObjects.Count; index++)
			{
				IInstantiate instantiate = initObjects[index].GetComponent<IInstantiate>();
				if (null != instantiate)
					InitItems.Add(instantiate);
			}
			for (int index = 0; index < InitItems.Count; index++)
			{
				try
				{
					InitItems[index].Inistantiate();
				}catch(System.Exception e)
				{
					Debug.LogError($"初始化失败 : {e.StackTrace}");
				}
			}
			JumpScene();
		}


		[SerializeField]
		int JumpLevelAfterInit = 0;
		void JumpScene()
		{
			if (JumpLevelAfterInit > 0)
			{
				SceneLevelManager.LoadLevel(JumpLevelAfterInit);
			}
		}
	}

	public interface IInstantiate
	{
		void Inistantiate();
	}
}